package cn.fzkj.springboot.controller;

import cn.fzkj.springboot.domain.Employee;
import cn.fzkj.springboot.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 1.开启基于注解的缓存, 主方法标注：@EnableCaching
 * 2.标注缓存注解
 *      Cacheable:方法可缓存的
 *      Cache
 */

@RestController
public class EmployeeController {

    @Autowired
    EmployeeService employeeService;

    @GetMapping("findAll")
    public Object findAll(){
        return employeeService.findAll();
    }

    @GetMapping("getOne/{id}")
    public Object getOne(@PathVariable("id") int id){
        return employeeService.getOne(id);
    }

    @PostMapping("insert")
    public Employee insert(@RequestBody Employee employee){
        return employeeService.insert(employee);
    }

    @PostMapping("update")
    public Employee update(@RequestBody Employee employee){
        return employeeService.update(employee);
    }

    @DeleteMapping("delEmp")
    public String delEmp(int id){
        employeeService.del(id);
        return "success";
    }



    @GetMapping("findByName")
    public Employee findByName(String name){
        return employeeService.getEmpByName(name);
    }


}
